//
//  YAYIOrderRefundsCell.m
//  YAYIDoctor
//
//  Created by hxp on 16/5/6.
//  Copyright © 2016年 hxp. All rights reserved.
//

#import "YAYIOrderRefundsCell.h"

@implementation YAYIOrderRefundsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createVies];
    }
    return self;
}


- (void)setFrame:(CGRect)frame
{
    frame.origin.y += 10;
    frame.size.height -= 10;
    [super setFrame:frame];
}


-(void)createVies{
    self.background = [UIView new];
//    self.background.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.background];
    
    self.title = [UILabel new];
    self.title.textColor = YAYIColor(87, 85, 85);
    self.title.font = [UIFont systemFontOfSize:font14];
    [self.background addSubview:self.title];
    
    self.name = [UILabel new];
    self.name.textColor = YAYIColor(87, 85, 85);
    self.name.font = [UIFont systemFontOfSize:font14];
    self.name.textAlignment = NSTextAlignmentRight;
    [self.background addSubview:self.name];
    
    self.icon = [UIImageView new];
    self.icon.image = [UIImage imageNamed:@"Icon_1"];
    [self.background  addSubview:self.icon];
    
    self.moneyText = [[UITextField alloc] init];
    self.moneyText.textAlignment = NSTextAlignmentCenter;
    self.moneyText.font = [UIFont systemFontOfSize:font14];
    self.moneyText.textColor = YAYIColor(83, 165, 243);
    [self.background addSubview:self.moneyText];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.background mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left);
        make.right.mas_equalTo(self.contentView.mas_right);
        make.top.mas_equalTo(self.contentView.mas_top).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_width, 45));
    }];
    
    if (self.row == 1){
        [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(20));
            make.centerY.mas_equalTo(self.contentView).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(120, 20));
        }];
        
        [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView.mas_right).with.offset(-20);
            make.centerY.mas_equalTo(self.contentView).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(100, 25));
        }];
        
        self.moneyText.layer.borderWidth = 0.5;
        self.moneyText.layer.borderColor = YAYIColor(83, 165, 243).CGColor;
        self.moneyText.clipsToBounds = YES;
        self.moneyText.layer.cornerRadius = 5;
        [self.moneyText mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView.mas_right).with.offset(-20);
            make.centerY.mas_equalTo(self.background.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(100, 30));
        }];
    }else if (self.row ==2) {
        [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(20));
            make.centerY.mas_equalTo(self.contentView).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(120, 20));
        }];
        [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView.mas_right).with.offset(-20);
            make.centerY.mas_equalTo(self.contentView).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(100, 25));
        }];
    }else if (self.row == 3){
//        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(20));
            make.centerY.mas_equalTo(self.contentView).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(120, 20));
        }];
        
        CGFloat rightMargin = 25;
        if (self.isDetail) {
            rightMargin = 20;
        }
        
        [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).with.offset(-rightMargin);
            make.centerY.mas_equalTo(self.contentView).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(200, 25));
        }];
        
        if (!self.isDetail) {
            [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(self.background.mas_right).with.offset(-14);
                make.centerY.mas_equalTo(self.contentView).with.offset(0);
                make.size.mas_equalTo(CGSizeMake(7, 12));
            }];
        }
    }
}


@end
